﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Liquid.Collections {
	/// <summary>
	/// Represents the method that will handle an event that represents an event on a set of items.
	/// </summary>
	/// <typeparam name="T">The type of the items in the set</typeparam>
	public delegate void ItemSetEventHandler<T>(object sender, ItemSetEventArgs<T> e);
	/// <summary>
	/// Provides data for an event that involves a set of items
	/// </summary>
	/// <typeparam name="T">The type of the items in the set</typeparam>
	public class ItemSetEventArgs<T> : EventArgs {
		/// <summary>
		/// Initializes a new instance of the <see cref="ItemSetEventArgs&lt;T&gt;"/> class, which is empty.
		/// </summary>
		public ItemSetEventArgs()
			: this(Enumerable.Empty<T>()) {
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ItemSetEventArgs&lt;T&gt;"/> class, containing a single item.
		/// </summary>
		/// <param name="item">The item.</param>
		public ItemSetEventArgs(T item)
			: this(Enumerable.Repeat(item, 1)) {
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ItemSetEventArgs&lt;T&gt;"/> class, with the specified items.
		/// </summary>
		/// <param name="set">The set.</param>
		public ItemSetEventArgs(IEnumerable<T> set) {
			this.m_Items = new List<T>(set);
		}

		/// <summary>
		/// Gets the items.
		/// </summary>
		/// <value>The items.</value>
		public ReadOnlyCollection<T> Items { get { return m_Items.AsReadOnly(); } }
		private List<T> m_Items;
	}
}
